package com.example.graduation.controller;


import com.example.graduation.entity.Torder;
import com.example.graduation.entity.User;
import com.example.graduation.form.IdForm;
import com.example.graduation.form.LongId;
import com.example.graduation.service.impl.OrderServiceImpl;
import com.example.graduation.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xyc
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderServiceImpl orderService;


    /**
     * @api {POST} /order/findShopOrder 查询商家订单信息
     * @apiVersion 1.0.0
     * @apiGroup OrderController
     * @apiName findShopOrder
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=6uP9wzKkNs
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findShopOrder")
    @ResponseBody
    public R findShopOrder(@RequestHeader String token) {
        List<Torder> shopOrder = orderService.findShopOrder(token);
        return R.ok().put("shopOrder", shopOrder);
    }


    /**
     * @api {POST} /order/findOrderById 根据id查询订单信息
     * @apiVersion 1.0.0
     * @apiGroup OrderController
     * @apiName findOrderById
     * @apiParam (请求体) {Number} id
     * @apiParamExample 请求体示例
     * {"id":7770}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findOrderById")
    @ResponseBody
    public R findOrderById(@RequestBody LongId id) {
        Torder torder = orderService.findOrderById(id.getId());
        return R.ok().put("torder", torder);
    }


    /**
     * @api {POST} /order/findUserById 根据订单号查询用户信息
     * @apiVersion 1.0.0
     * @apiGroup OrderController
     * @apiName findUserById
     * @apiParam (请求体) {Number} id
     * @apiParamExample 请求体示例
     * {"id":2856}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findUserById")
    @ResponseBody
    public R findUserById(@RequestBody LongId id) {
        User user = orderService.findUserById(id.getId());
        return R.ok().put("user", user);
    }


}

